package com.yyy.controller;



import com.yyy.entity.TbSpecification;
import com.yyy.sevice.TbSpecificationService;
import com.yyy.util.PageResult;
import com.yyy.util.R;
import com.yyy.vo.TbSpecificationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/specification")
@CrossOrigin
public class TbSpecificationController {

    @Autowired
    private TbSpecificationService tbSpecificationService;

    //查询所有
    @GetMapping("/list")
    public List<TbSpecification> list(){
        return tbSpecificationService.findAll();
    }

    //分页查询
    @GetMapping("/findByPage")
    public PageResult<TbSpecification> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return tbSpecificationService.findByPage(page, pageSize);
    }

    //输入查询带分页
    @PostMapping("/search")
    public PageResult<TbSpecification> search(@RequestParam("page") Integer page,
                                              @RequestParam("pageSize") Integer pageSize,
                                              @RequestBody(required = false) TbSpecificationVo tbSpecificationVo){
        System.out.println(tbSpecificationVo);
        return tbSpecificationService.search(page, pageSize, tbSpecificationVo);
    }

    //保存
    @PostMapping("/save")
    public R save(@RequestBody TbSpecification tbSpecification){
        System.out.println(tbSpecification);
        return tbSpecificationService.save(tbSpecification) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
}
